package com.pro.common.service.admin.model.db;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.pro.common.api.CommonConst;
import com.pro.common.api.enums.EnumSysRole;
import com.pro.common.api.model.BaseModel;
import com.pro.common.api.model.ILoginInfo;
import com.pro.common.api.model.auth.IAdminClass;
import com.pro.framework.api.enums.IEnumToDbDbId;
import com.pro.framework.javatodb.annotation.JTDField;
import com.pro.framework.javatodb.annotation.JTDTable;
import com.pro.framework.javatodb.constant.JTDConst;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;

/**
 * 管理员表
 *
 * @author admin
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Schema(description = "管理员")
@JTDTable(entityId = 10001, sequences = {"KEY `idx_username` (`username`)"}, module = CommonConst.Modules.admin)
public class Admin extends BaseModel implements IAdminClass, ILoginInfo, IEnumToDbDbId {

    @Schema(description = "登录名")
    private String username;
    @Schema(description = "登录密码")
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @JTDField(uiType = JTDConst.EnumFieldUiType.password)
    private String password;
    @Schema(description = "昵称")
    @JTDField(notNull = JTDConst.EnumFieldNullType.can_null)
    private String nickname;
    @Schema(description = "手机号")
    @JTDField(notNull = JTDConst.EnumFieldNullType.can_null)
    private String phone;
    @Schema(description = "ip")
    @JTDField(notNull = JTDConst.EnumFieldNullType.can_null)
    private String ip;
    @Schema(description = "ip地址信息")
    @JTDField(notNull = JTDConst.EnumFieldNullType.can_null)
    private String ipAddress;
    @Schema(description = "登录次数")
    private Integer loginTimes;
    @JTDField(notNull = JTDConst.EnumFieldNullType.can_null)
    @Schema(description = "最后登录时间")
    private LocalDateTime lastLoginTime;
    @Schema(description = "启用")
    private Boolean enabled;
    //    @Schema(description = "谷歌验证器")
//    private Boolean googleAuthOpen;
    @Schema(description = "谷歌验证器密钥")
    @JTDField(notNull = JTDConst.EnumFieldNullType.can_null)
    private String googleAuthSecret;
    @Schema(description = "绑定角色")
    @JTDField(entityName = "siteContent.authRole", entityClassKey = "id", entityClassTargetProp = "id", javaTypeEnumClassMultiple = true, entityClassLabel = "roleName")
    private String roleIds;
    @Schema(description = "添加店铺权限分组")
    @JTDField(entityName = "siteContent.authRouteGroup", defaultValue = "DEFAULT", entityClassLabel = "groupName")
    private String authRouteGroupCode;


    @Override
    @JsonIgnore
    public EnumSysRole getSysRole() {
        return EnumSysRole.ADMIN;
    }

    @Override
    public Boolean getIsGuest() {
        return false;
    }

    @Override
    public Boolean getIsDemo() {
        return true;
    }

    // 旧密码
//    transient private String passwordOld;
}
